package com.konne.nightmare.FastPublicOpinion.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.konne.nightmare.FastPublicOpinion.R;

/**
 * Create by ws.
 * on Data:2022/2/11  Time:下午 4:17.
 * description: ** .
 */
public class LocalUploadDialog extends Dialog {
    private LocalUploadListener localUploadListener;
    public LocalUploadDialog(@NonNull Context context) {
        super(context, R.style.ActionSheetDialogStyle);
    }

    public LocalUploadDialog setLocalUploadListener(LocalUploadListener localUploadListener) {
        this.localUploadListener = localUploadListener;
        return this;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_local_upload);
        Window dialogWindow = getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        dialogWindow.setAttributes(lp);
        dialogWindow.setGravity(Gravity.BOTTOM);
        findViewById(R.id.stv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        findViewById(R.id.stv_submit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        ViewGroup ll_content=findViewById(R.id.ll_content);
        View view1=ll_content.getChildAt(0);
        view1.setTag(0);
        view1.setOnClickListener(itemOnClock);
        View view2=ll_content.getChildAt(2);
        view2.setTag(1);
        view2.setOnClickListener(itemOnClock);
        View view3=ll_content.getChildAt(4);
        view3.setTag(2);
        view3.setOnClickListener(itemOnClock);
    }
    private View.OnClickListener itemOnClock=new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dismiss();
            if(localUploadListener!=null){
                localUploadListener.localUpload((Integer) view.getTag());
            }
        }
    };
    public interface LocalUploadListener{
        void localUpload(int type);
    }
}
